package operation;//因为管理员和普通用户操作存在不同，所以要是操作卸载BookList不好区分

import book.Book;
import book.BookList;

import java.util.Scanner;

//从书架也就是books数组里面找书
public class FindBook implements IOperation,IScanner{
    @Override
    public void work(BookList books) {
        System.out.println("查找图书————");
        System.out.println("请输入您要查找的图书名称：");
        String name=scannerName();
        int currentSize= books.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book=books.getBook(i);
            if(book.getName().equals(name)){
                System.out.println("找到这本书籍，书籍信息如下");
                System.out.println(book);
                return;
            }
        }
        System.out.println("没有找到《" + name + "》这本书");
    }

    //AddBook里面查找图书的方法
    public boolean work(Book book) {
        String name=book.getName();
        BookList books=new BookList();
        int currentSize= books.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book_=books.getBook(i);
            if(book_.getName().equals(name)){
                return true;
            }
        }
        return false;
    }

    //DelBook里面查找图书的方法
    public int work(String name,BookList books) {
        //BookList books=new BookList();为什么有这段代码后面currentSize为3，因为这里调用了构造函数，在构造函数里，usedSize设置成了3
        //所以public int work(String name)变成public int work(String name,BookList books)
        int currentSize= books.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book_=books.getBook(i);
            if(book_.getName().equals(name)){
                return i;
            }
        }
        return -1;
    }

}
